public class StopTest extends Thread{
    public static boolean flag=true;

    @Override
    public void run() {
        int i=0;
        while (flag){
            System.out.println(Thread.currentThread().getName()+",i="+i);
            i++;

        }
    }

    public static void main(String[] args) {
        Thread thread=new StopTest();
        thread.start();

        //运行到10停止线程
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName()+",i="+i);
            if(i==10){
                System.out.println(Thread.currentThread().getName()+"设置开关为false");
                flag=false;
                Thread.yield();



            }

        }
    }
}
